package com.zhu.rpc;

import com.zhu.rpc.exception.UnrecognizedMsgException;
import com.zhu.rpc.msgBean.RpcRequestBean;
import com.zhu.rpc.msgBean.RpcResponseBean;
import com.zhu.rpc.msgBean.ServerInitBean;
import com.zhu.rpc.server.RpcProtocolProviderBean;

public enum  MsgType {
    //心跳消息
    heartBeat(10,Integer.class),
    //初始化消息
    init(11, ServerInitBean.class),
    //远程调用消息
    callReq(12, RpcProtocolProviderBean.class),
    //远程重试发送消息
    callReReq(13, RpcProtocolProviderBean.class),
    callResp(14, RpcResponseBean.class);
    public int id;
    public Class msgBean;

    MsgType(int id,Class<?> msgBean){
        this.id = id;
        this.msgBean = msgBean;
    }

    public static MsgType getTypeById(int id){
        for (MsgType msgType: MsgType.values()) {
            if (msgType.id == id){
                return msgType;
            }
        }
        throw new UnrecognizedMsgException(id);
    }
}
